from rest_framework.generics import ListCreateAPIView
from rest_framework.permissions import DjangoModelPermissions, IsAdminUser

from apps.users.models import User
from apps.wthg_admin.serializers.users import UserModelSerializer
from apps.wthg_admin.serializers.users import UserPageNumberPagination

class UserAPIView(ListCreateAPIView):
    """用户列表展示"""
    # queryset = User.objects.all()
    serializer_class=UserModelSerializer
    pagination_class = UserPageNumberPagination


    #根据业务逻辑指定查询结果集
    def get_queryset(self):
        keyword=self.request.query_params.get('keyword')
        if keyword == '' or keyword is None: #判断是否搜索框搜索，如果没有搜索，返回全部
            return User.objects.filter(is_staff=False)
        return User.objects.filter(username__contains=keyword) #模糊查询





